{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "samples = []  # 初始化样本列表\n",
    "for label, class_idx in enumerate(range(0,24)):\n",
    "    # 获取当前类别的目录路径\n",
    "    class_path = os.path.join('/media/ubuntu/Data/huyanlong/ZJU_NPY_50ms', str(class_idx))\n",
    "    \n",
    "    # 使用 os.scandir() 遍历目录中的所有文件\n",
    "    with os.scandir(class_path) as entries:\n",
    "        file_paths = [entry.path for entry in entries if entry.is_file()]  # 获取文件路径列表\n",
    "    \n",
    "    # 生成标签列表\n",
    "    labels = [label] * len(file_paths)  # 使用乘法生成与文件数量相同的标签列表\n",
    "    \n",
    "    # 将文件路径和标签配对，添加到样本列表中\n",
    "    samples.extend(zip(file_paths, labels))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "load dataset:: 2it [00:00, 496.81it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([1, 512, 512]) 0\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "from data import BaseDataset\n",
    "\n",
    "dataset = BaseDataset(data_path='/media/ubuntu/Data/huyanlong/ZJU_NPY_50ms', logger=None,select_class=[1,2])\n",
    "\n",
    "for x, y in dataset:\n",
    "    print(x.shape,y)\n",
    "    break"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch_hjf",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
